# 1.字符%
name = "小明"
result = "你好，我叫%s。" % name
print(result)

name = "小明"
age = 12
result = "你好，我叫%s，今年我%d岁了。" % (name, age)
print(result)

# 2.format()方法
name = "小明"
result = "你好，我的名字是{}。" .format(name)
print(result)

name = "小明"
age = 12
result_one = "你好，我的名字是{}，今年我{}岁了。" .format(name, age)
print(result_one)
result_two = "你好，我的名字是{1}，今年我{0}岁了。" .format(age, name)
print(result_two)

# 保留n位小数
pi = 3.1415
result = "{:.2f}".format(pi)
print(result)

# 数字补齐
num = 1
result = "{:0>3d}".format(num)
print(result)

# 显示百分比
num = 0.1
result = "{:.0%}".format(num)
print(result)

# 3.f-strings
address = '北京'
result = f'欢迎来到{address}。'
print(result)

name = '小天'
age = 20
gender = '男'
result = f'我的名字是{name}，今年{age}岁了，我的性别是{gender}。'
print(result)